package com.tracy.lifeproject.discovery.goods.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.tracy.lifeproject.R;
import com.tracy.lifeproject.bean.BuyerRecordBean;
import com.tracy.lifeproject.discovery.adapter.BuyerRecyclerAdapter;
import com.tracy.lifeproject.utils.CircleImageView;

import java.util.List;

/**
 * Created by ZJS on 2016/7/24.
 */
public class BuyerRecordAdapter extends RecyclerView.Adapter<BuyerRecordAdapter.MyBuyerViewHolder> {

    private List<BuyerRecordBean.DataBean.FavoriteListsBean> mDatas;
    private Context mContext;

    public BuyerRecordAdapter(Context context,List<BuyerRecordBean.DataBean.FavoriteListsBean> datas){
        this.mContext = context;
        this.mDatas = datas;
    }

    @Override
    public MyBuyerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_buyerrecord,null);
        return new MyBuyerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyBuyerViewHolder holder, int position) {
        BuyerRecordBean.DataBean.FavoriteListsBean favoriteListsBean = mDatas.get(position);
        holder.buyerMassage.setText(favoriteListsBean.getName());
        holder.buyerName.setText(favoriteListsBean.getUser_info().getNickname());
        holder.buyCount.setText(favoriteListsBean.getItems_count()+"个单品");
        Picasso.with(mContext).load(favoriteListsBean.getUser_info().getAvatar_url()).into(holder.buyerIcon);
        BuyerRecyclerAdapter adapter = new BuyerRecyclerAdapter(mContext,favoriteListsBean.getItems_info());
        holder.buyerRecordImages.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.HORIZONTAL,false));
        holder.buyerRecordImages.setAdapter(adapter);
//        holder.buyerRecordImages.setLayoutManager(new StaggeredGridLayoutManager());
    }

    @Override
    public int getItemCount() {
        return mDatas==null?0:mDatas.size();
    }

    public class MyBuyerViewHolder extends RecyclerView.ViewHolder{

        private TextView buyerMassage,buyerName,buyCount;
        private CircleImageView buyerIcon;
        private RecyclerView buyerRecordImages;

        public MyBuyerViewHolder(View itemView) {
            super(itemView);
            buyerMassage = (TextView) itemView.findViewById(R.id.txt_item_buyerMassage);
            buyerName = (TextView) itemView.findViewById(R.id.buyerName);
            buyCount = (TextView) itemView.findViewById(R.id.txt_item_buyConut);
            buyerIcon = (CircleImageView) itemView.findViewById(R.id.img_buyerIcon);
            buyerRecordImages = (RecyclerView) itemView.findViewById(R.id.recycler_buyerRecordImages);
        }
    }
}
